﻿Public Class informeCCliente
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        Me.Close()
    End Sub

    Private Sub informeCCliente_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CargarCmb()
        LimpiarFormulario()
    End Sub
    Private Sub LimpiarFormulario()
        txtApe.Text = ""
        txtCuit.Text = ""
        txtDir.Text = ""
        txtDNI.Text = ""
        txtEmail.Text = ""
        txtNoDir.Text = ""
        txtNom.Text = ""
        txtNroClie.Text = ""
        txtPiso.Text = ""
        txtTel.Text = ""
        cmbTipoCli.SelectedIndex = 0
        cmbSucursal.SelectedIndex = 0
    End Sub

    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        LimpiarFormulario()
    End Sub
    Private Sub CargarCmb()
        cmbTipoCli.Items.Add("PARTICULAR")
        cmbTipoCli.Items.Add("EMPRESA")
        cmbTipoCli.SelectedIndex = 0
    End Sub
    Private Sub TraeConsulta(ByVal ListaClientes As List(Of clsCliente))
        consultaCliente.ModoAcceso = "INFORME CLIENTE"
        consultaCliente.grdClientes.DataSource = ListaClientes

        consultaCliente.grdClientes.Columns(0).DataPropertyName = "Cli_Id"
        consultaCliente.grdClientes.Columns(1).DataPropertyName = "Apellido"
        consultaCliente.grdClientes.Columns(2).DataPropertyName = "Nombre"
        consultaCliente.grdClientes.Columns(3).DataPropertyName = "Dni"
        consultaCliente.grdClientes.Columns(4).DataPropertyName = "Email"
        consultaCliente.grdClientes.Columns(5).DataPropertyName = "Cuit"
        consultaCliente.grdClientes.Columns(6).DataPropertyName = "Direccion"
        consultaCliente.grdClientes.Columns(7).DataPropertyName = "Altura"
        consultaCliente.grdClientes.Columns(8).DataPropertyName = "Depto"
        consultaCliente.grdClientes.Columns(9).DataPropertyName = "Tel"

        consultaCliente.grdClientes.Columns(10).DataPropertyName = "Tipo"
        consultaCliente.grdClientes.Columns(11).DataPropertyName = "Cod_suc"

        consultaCliente.grdClientes.Columns(0).HeaderText = "Codigo"
        consultaCliente.grdClientes.Columns(1).HeaderText = "Apellido"
        consultaCliente.grdClientes.Columns(2).HeaderText = "Nombre"
        consultaCliente.grdClientes.Columns(3).HeaderText = "DNI"
        consultaCliente.grdClientes.Columns(4).HeaderText = "Email"
        consultaCliente.grdClientes.Columns(5).HeaderText = "CUIT/CUIL"
        consultaCliente.grdClientes.Columns(6).HeaderText = "Direccion"
        consultaCliente.grdClientes.Columns(7).HeaderText = "Nro."
        consultaCliente.grdClientes.Columns(8).HeaderText = "Depto."
        consultaCliente.grdClientes.Columns(9).HeaderText = "Telefono"

        consultaCliente.grdClientes.Columns(10).HeaderText = "Tipo"
        consultaCliente.grdClientes.Columns(11).HeaderText = "Codigo Sucursal"

        consultaCliente.grdClientes.Columns(10).Visible = False
        consultaCliente.grdClientes.Columns(11).Visible = False

        consultaCliente.MdiParent = Me.MdiParent
        Me.Enabled = False
        consultaCliente.Show()
    End Sub

    Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Dim ClienteBusiness As New businessCliente()
        Dim ListaClientes As New List(Of clsCliente)
        Dim Cod_Suc As Int32
        Dim Cli_Id As Int32
        Dim DNI As String
        Dim CUIT As String
        Dim Nombre As String
        Dim Apellido As String
        Dim Direccion As String
        Dim DirNro As String
        Dim DirDepto As String
        Dim Telefono As String
        Dim Email As String
        Dim Tipo As String

        Try
            ''cli_id
            If txtNroClie.Text.Trim.Length > 0 Then
                Cli_Id = Convert.ToInt32(txtNroClie.Text.Trim)
            Else
                Cli_Id = 0
            End If


            DNI = txtDNI.Text.Trim.ToUpper
            CUIT = txtCuit.Text.Trim.ToUpper
            Nombre = txtNom.Text.Trim.ToUpper
            Apellido = txtApe.Text.Trim.ToUpper
            Direccion = txtDir.Text.Trim.ToUpper
            DirNro = txtNoDir.Text.Trim.ToUpper
            DirDepto = txtPiso.Text.Trim.ToUpper
            Telefono = txtTel.Text.Trim.ToUpper
            Email = txtEmail.Text.Trim.ToUpper

            Select Case cmbSucursal.Text
                Case "SUCURSAL 1"
                    Cod_Suc = 1
                Case "SUCURSAL 2"
                    Cod_Suc = 2
                Case "CASA CENTRAL"
                    Cod_Suc = 3
            End Select

            Select Case cmbTipoCli.Text.Trim
                Case "PARTICULAR"
                    Tipo = "P"
                Case "EMPRESA"
                    Tipo = "E"
                Case Else
                    Tipo = "P"
            End Select

            'aca me tira error
            ListaClientes = ClienteBusiness.ConsultaCliente(Cli_Id, DNI, CUIT, Nombre, Apellido, Direccion, DirNro, DirDepto, Telefono, Email, Tipo, Cod_Suc)
            If ListaClientes.Count > 0 Then
                TraeConsulta(ListaClientes)
            Else
                MessageBox.Show("No hay datos para mostrar con los parametros ingresados", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
        End Try
    End Sub
End Class
